package com.util;


import java.util.Calendar;
import java.text.SimpleDateFormat;
import java.text.ParseException;



public final class DateOperations {
    
    public static String DATE = "dd-MM-yyyy"; 
    public static String DATETIME = "dd-MM-yyyy HH:mm";

    private DateOperations() {
    }

    public final static String toString(Calendar date) {
        String sDate = null;
        if (date != null) {

            SimpleDateFormat dateFormat = new SimpleDateFormat(DATE);
            sDate = dateFormat.format(date.getTime());
        }
        return sDate;
    }
    
	/* El parametro dateAsString debe tener el patron dd-mm-yyyy */
	public final static Calendar toCalendar(String dateAsString) 
		throws ParseException{
	
		SimpleDateFormat dateFormat = new SimpleDateFormat(DATE);
		Calendar date = Calendar.getInstance();
		date.clear();
		date.setTime(dateFormat.parse(dateAsString));
		
		return date;
		
	}
       
	public final static Calendar toCalendar(String dateAsString, String pattern) 
		throws ParseException{
		SimpleDateFormat dateFormat = new SimpleDateFormat(pattern);
		Calendar date = Calendar.getInstance();
		date.clear();
		date.setTime(dateFormat.parse(dateAsString));
		
		return date;
		
	}

    public final static String toString(Calendar date, String pattern) {
        String sDate = null;
        if (date != null) {

            SimpleDateFormat dateFormat = new SimpleDateFormat(pattern);
            sDate = dateFormat.format(date.getTime());
        }
        return sDate;
    }
    
	/**
     * 
     */
	public final static Calendar getDateWithoutTime(Calendar date) throws ParseException{

		Calendar dateWithoutTime = DateOperations.toCalendar(DateOperations.toString(date));
				
		return dateWithoutTime;
	
	}
       

}